package com.zking.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zking.frame.LYK.JDBC;

public class GetFilmAllData {

	/**
	 * 
	 * 通过图片的路径得到所有的电影信息
	 * 
	 * */
	public static Map<String ,Object> getFilmData(String film_imgSrc){
	
		Map<String ,Object> map=new HashMap<String ,Object>();
		
		Connection conn= JDBC.getConn();
		PreparedStatement pst =null;
		ResultSet rs=null;
		String sql="select * from film where film_imgSrc=?";
		try {
			pst=conn.prepareStatement(sql);
			pst.setString(1, film_imgSrc);
			rs=pst.executeQuery();
			while(rs.next()){
				String film_name=rs.getString("film_name");
				map.put("电影名", film_name);
				float film_score=rs.getFloat("film_score");
				map.put("评分", film_score);
				String director=rs.getString("director");
				map.put("导演", director);
				String performer=rs.getString("performer");
				map.put("演员", performer);

				String film_type=rs.getString("film_type");
				map.put("电影类型", film_type);
				String film_region=rs.getString("film_region");
				map.put("地区", film_region);
				
				int  film_duration=rs.getInt("film_duration");
				map.put("片长", film_duration);
				String film_introduce=rs.getString("film_introduce");
				map.put("电影介绍", film_introduce);
				String film_rescheduled=rs.getString("film_rescheduled");
				map.put("上映时间", film_rescheduled);
				
				
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			ColseSql.colseAllsql(pst, rs, conn);
		}
		
		
		return map;
	}
	
	public static Map<String ,Object> getFilmDataByName(String filmName){
		
		Map<String ,Object> map=new HashMap<String ,Object>();
		
		Connection conn= JDBC.getConn();
		PreparedStatement pst =null;
		ResultSet rs=null;
		String sql="select * from film where film_name=?";
		try {
			pst=conn.prepareStatement(sql);
			pst.setString(1, filmName);
			rs=pst.executeQuery();
			while(rs.next()){
				String film_name=rs.getString("film_name");
				map.put("电影名", film_name);
				float film_score=rs.getFloat("film_score");
				map.put("评分", film_score);
				String director=rs.getString("director");
				map.put("导演", director);
				String performer=rs.getString("performer");
				map.put("演员", performer);
				
				String film_type=rs.getString("film_type");
				map.put("电影类型", film_type);
				String film_region=rs.getString("film_region");
				map.put("地区", film_region);
				int film_id=rs.getInt("film_id");
				map.put("id", film_id);
				int  film_duration=rs.getInt("film_duration");
				map.put("片长", film_duration);
				String film_introduce=rs.getString("film_introduce");
				map.put("电影介绍", film_introduce);
				String film_rescheduled=rs.getString("film_rescheduled");
				map.put("上映时间", film_rescheduled);
				String film_imgSrc=rs.getString("film_imgSrc");
				map.put("图片", film_imgSrc);
				
				
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			ColseSql.colseAllsql(pst, rs, conn);
		}
		
		
		return map;
	}
	
	public static void main(String[] args) {
		Map<String ,Object> map=getFilmData("imges/homepic3.png");
		System.out.println(map.get("导演"));
		
	}
 }
